package com.zy.settings.fragment

import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.FragmentManager
import com.zy.net.data.DataRecord
import com.zy.net.data.Record
import com.zy.settings.R

class DataBackupHistoryViewAdapter(
    private val fragmentManager: FragmentManager
) : RecyclerView.Adapter<DataBackupHistoryViewAdapter.ViewHolder>() {

    private val values = mutableListOf<Record>()

    fun updateData(dataRecord: DataRecord) {
        values.addAll(dataRecord.data)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {

        return ViewHolder(
            LayoutInflater.from(parent.context)
                .inflate(R.layout.fragment_data_backup_history_list_item, parent, false)
        )
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bind(values[position])
    }

    override fun getItemCount(): Int = values.size

    inner class ViewHolder(view: View) :
        RecyclerView.ViewHolder(view) {
        private val itemContent: TextView = view.findViewById(R.id.backup_history_list_item_title)

        init {

        }

        fun bind(record: Record) {
            itemContent.text = record.date
        }
    }

}